package com.zyj.persion.controller;

import java.util.ArrayList;
import java.util.List;

import com.zyj.assets.domain.AssetsInfo;
import com.zyj.common.annotation.Log;
import com.zyj.common.core.controller.BaseController;
import com.zyj.common.core.domain.AjaxResult;
import com.zyj.common.core.page.TableDataInfo;
import com.zyj.common.enums.BusinessType;
import com.zyj.common.utils.poi.ExcelUtil;
import com.zyj.persion.domain.AssetsPresion;
import com.zyj.persion.service.IAssetsPresionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 人员资产Controller
 * 
 * @author zhuyujie
 * @date 2022-05-09
 */
@Controller
@RequestMapping("/assets/presion")
public class AssetsPresionController extends BaseController
{
    private String prefix = "assets/persion";

    @Autowired
    private IAssetsPresionService assetsPresionService;

    @GetMapping()
    public String presion()
    {
        return prefix + "/presion";
    }

    /**
     * 查询人员资产列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AssetsPresion assetsPresion)
    {
        startPage();
        List<AssetsInfo> list = assetsPresionService.selectAssetsPresionByAssetsPersionId(assetsPresion.getUserId());
        if(list ==null ){
            return getDataTable(new ArrayList<AssetsInfo>());
        }
        return getDataTable(list);
    }

    /**
     * 查询资产列表
     */
    @PostMapping("/listSearch")
    @ResponseBody
    public TableDataInfo listSearch(AssetsInfo assetsInfo)
    {
        startPage();
        List<AssetsInfo> list = assetsPresionService.selectAllAssets(assetsInfo);
        if(list ==null ){
            return getDataTable(new ArrayList<AssetsInfo>());
        }
        return getDataTable(list);
    }

    /**
     * 导出人员资产列表
     */
    @Log(title = "人员资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AssetsPresion assetsPresion)
    {
        List<AssetsPresion> list = assetsPresionService.selectAssetsPresionList(assetsPresion);
        ExcelUtil<AssetsPresion> util = new ExcelUtil<AssetsPresion>(AssetsPresion.class);
        return util.exportExcel(list, "人员资产数据");
    }

    /**
     * 新增人员资产
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }


    @GetMapping("/assetsSearch")
    public String assetsSearch()
    {
        return prefix + "/assetsSearch";
    }

    /**
     * 新增保存人员资产
     */
    @Log(title = "人员资产", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AssetsPresion assetsPresion)
    {
        return toAjax(assetsPresionService.insertAssetsPresion(assetsPresion));
    }

    /**
     * 修改人员资产
     */
    @GetMapping("/edit/{assetsPersionId}")
    public String edit(@PathVariable("assetsPersionId") Long assetsPersionId, ModelMap mmap)
    {
//        AssetsPresion assetsPresion = assetsPresionService.selectAssetsPresionByAssetsPersionId(assetsPersionId);
//        mmap.put("assetsPresion", assetsPresion);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员资产
     */
    @Log(title = "人员资产", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AssetsPresion assetsPresion)
    {
        return toAjax(assetsPresionService.updateAssetsPresion(assetsPresion));
    }

    /**
     * 删除人员资产
     */
    @Log(title = "人员资产", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(assetsPresionService.deleteAssetsPresionByAssetsPersionIds(ids));
    }
}
